<?php


namespace Staff\Model;


use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterInterface;

class Staff
{
    public $staff_id, $staff_name, $staff_tel, $start_time, $bank_name, $bank_city;
    protected $inputFilter;     // <-- Add this variable

    public function exchangeArray($data)
    {
        foreach ($this as $key => $val) {
            $this->$key = empty($data[$key]) ? null : $data[$key];
        }
//        $this->staff_id = (!empty($data['staff_id'])) ? $data['staff_id'] : null;
//        $this->staff_name = (!empty($data['staff_name'])) ? $data['staff_name'] : null;
//        $this->staff_tel = (!empty($data['staff_tel'])) ? $data['staff_tel'] : null;
//        $this->start_time = (!empty($data['start_time'])) ? $data['start_time'] : null;
//        $this->bank_name = (!empty($data['bank_name'])) ? $data['bank_name'] : null;
//        $this->bank_city = (!empty($data['bank_city'])) ? $data['bank_city'] : null;
    }

    // Add the following method
    public function getArrayCopy()
    {
        return get_object_vars($this);
    }

    // Add content to these methods
    public function setInputFilter(InputFilterInterface $inputFilter)
    {
        throw new \Exception('Not used');
    }

    public function getInputFilter()
    {
        if (!$this->inputFilter) {
            $this->inputFilter = new InputFilter();
            $this->inputFilter->add(array(
                'name' => 'staff_id',
                'required' => true,
                'filters' => array(
                    array('name' => 'StringLength')
                )
            ));
            $this->inputFilter->add(array(
                'name' => 'staff_name',
                'required' => true,
                'filters' => array(
                    array('name' => 'StripTags'),
                    array('name' => 'StringTrim')
                ),
                'validators' => array(
                    array(
                        'name' => 'StringLength',
                        'options' => array(
                            'encoding' => 'UTF-8',
                            'min' => 1,
                            'max' => 100
                        )
                    )
                )
            ));
            $this->inputFilter->add(array(
                'name' => 'staff_tel',
                'required' => true,
                'filters' => array(
                    array('name' => 'StripTags'),
                    array('name' => 'StringTrim')
                ),
                'validators' => array(
                    array(
                        'name' => 'StringLength',
                        'options' => array(
                            'encoding' => 'UTF-8',
                            'min' => 1,
                            'max' => 100
                        )
                    )
                )
            ));
        }
        return $this->inputFilter;
    }
}